package com.epsilon.pos.proveedores.delegator;

import org.eclipse.swt.widgets.Shell;

import com.epsilon.pos.proveedores.events.ProveedorEventDelegate;
import com.epsilon.pos.proveedores.model.Proveedor;
import com.epsilon.pos.proveedores.view.ProveedorShell;

public class ProveedorControl {

	private ProveedorEventDelegate	delegate;

	private ProveedorControl( ProveedorEventDelegate delegate ) {
		this.delegate = delegate;
	}

	public Proveedor getProveedor() {
		return delegate.getProveedor();
	}

	public ProveedorShell getProveedorShell() {
		return delegate.getProveedorShell();
	}

	public static ProveedorControl getInstance( Shell parent ) {
		ProveedorShell proveedorShell = new ProveedorShell( parent );
		ProveedorEventDelegate events = new ProveedorEventDelegate( proveedorShell );
		setEvents( proveedorShell, events );

		return new ProveedorControl( events );
	}

	private static void setEvents( ProveedorShell proveedorShell, ProveedorEventDelegate events ) {

		proveedorShell.addKeyListener( events.getEventoAlPresionarTeclas() );

		proveedorShell.getProveedorComposite().getTxtNombre().addKeyListener( events.getEventoAlPresionarTeclas() );
		proveedorShell.getProveedorComposite().getTxtContacto().addKeyListener( events.getEventoAlPresionarTeclas() );
		proveedorShell.getProveedorComposite().getTxtContacto()
				.addFocusListener( events.getEventoAlEnfocarTxtContacto() );
		proveedorShell.getProveedorComposite().getTxtObservaciones()
				.addKeyListener( events.getEventoAlPresionarTeclas() );

		proveedorShell.getProveedorComposite().getBtnAgregar().addSelectionListener( events.getEventoBtnAgregar() );
		proveedorShell.getProveedorComposite().getBtnAgregar().addKeyListener( events.getEventoAlPresionarTeclas() );

		proveedorShell.getProveedorComposite().getBtnCancelar().addSelectionListener( events.getEventoBtnCancelar() );
		proveedorShell.getProveedorComposite().getBtnCancelar().addKeyListener( events.getEventoAlPresionarTeclas() );
	}
}